/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ivanbiz.service;

import com.ivanbiz.dao.DaftarKelasDAO;
import com.ivanbiz.dao.KelasDAO;
import com.ivanbiz.dao.impl.DaftarKelasDAOImpl;
import com.ivanbiz.model.DaftarKelas;
import com.ivanbiz.model.Kelas;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.select.SelectorComposer;

/**
 *
 * @author IW20149X
 */
public class DaftarKelasLaporanPrintService extends SelectorComposer<Component> {

    KelasDAO kelasDAO;
    DaftarKelasDAO daftarKelasDAO;
    SimpleDateFormat sdf = new SimpleDateFormat("dd MMM yyyy");
//    @Wire
//    Jasperreport report;
    SimpleDateFormat simpleDateFormat;
    SimpleDateFormat simpleDateFormatFrom;

    @Override
    public void doAfterCompose(Component comp) throws Exception {
        super.doAfterCompose(comp);
        daftarKelasDAO = new DaftarKelasDAOImpl();
        simpleDateFormat = new SimpleDateFormat("dd MMMMM yyyy");
        simpleDateFormatFrom = new SimpleDateFormat("MMM dd, yyyy");
        Kelas kelas = (Kelas) Executions.getCurrent().getArg().get("kelas");
        loadReport(kelas);
    }

    private void loadReport(Kelas kelas) {
        try {
            List<DaftarKelas> listDaftarKelas = daftarKelasDAO.getDataByEqualsOrderByBankAndNama(kelas.getTransactionReference());
            Map map = new HashMap();
            map.put("logo", Executions.getCurrent().getDesktop().getWebApp().getRealPath("/img/logo.jpg"));
            map.put("kelas.tempatKelas", kelas.getTempatKelas() + " , " + simpleDateFormat.format(kelas.getTanggalKelas()));
            map.put("kelas.tanggalFrom", simpleDateFormatFrom.format(kelas.getTanggalKelas()));
//            report.setType("pdf");
//            report.setSrc("/report/DaftarKelasReport.jasper");
//            report.setParameters(map);
//            report.setDatasource(new JRBeanCollectionDataSource(listDaftarKelas));
        } catch (Exception ex) {
            Logger.getLogger(DaftarKelasLaporanPrintService.class.getName()).log(Level.SEVERE, null, ex);
        }


    }
}
